package com.manage.web.data;

import com.manage.common.util.*;
import com.manage.common.util.dataFunction.*;
import com.manage.model.dto.StaffDTO;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 生产测试数据工具类
 * @author duaiyu
 * @version V1.0
 * @date 2022/2/20
 * 来源：自研
 */
public class CreateTestData {

    //用static修饰来模拟公用一个订单编号
    private static OrderCodeGenerator ocg = new OrderCodeGenerator();

    //对外开放生产staff接口
    public static List<StaffDTO> createStaffTestData(AtomicInteger id, AtomicInteger ac){
        List<StaffDTO> list = new ArrayList<>();
        for(int i = 0; i < 500; i++){
            StaffDTO sf = createStaff(id, ac);
            System.out.println("sf=[ " + sf.toString() + " ]");
            list.add(sf);
        }
        return list;
    }

    //生产staff对象
    public static StaffDTO createStaff(AtomicInteger id, AtomicInteger ac){
        StaffDTO sd = new StaffDTO();
        sd.setId(createOrder(id));
        sd.setStaffId(createAccount(ac));
        sd.setName(CreateNameUtil.getName());
        sd.setBrithday(CreateDate.getDate());
        sd.setEducation(CreateEducation.getEducation());
        sd.setPhone(CreatePhone.getPhone());
        sd.setNation(CreateNation.getNation());
        sd.setWork(getPosition());
        sd.setWifePhone(CreatePhone.getPhone());
        sd.setOtherFamily(CreatePhone.getPhone());
        sd.setIdCard(CreateIdCard.getIdCard());
        sd.setSex(getSex());
        sd.setPosition(getPosition());
        sd.setCompany(getCompany());
        return sd;
    }

    //生产主键id
    public static String createOrder(AtomicInteger id) {
        int result = id.incrementAndGet();
        return String.valueOf(result);
    }
    //生成用户账号
    public static String createAccount(AtomicInteger ac) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return sdf.format(date) + ac.incrementAndGet();
    }

    //生产StaffId
    public static String createStaffId(AtomicInteger ai){
        ai.incrementAndGet();
        return String.valueOf(ai);
    }

    //生成身份证
    public static String getSex(){
        Integer num = new Random().nextInt(2);
        String[] sex = {"男", "女"};
        return sex[num];
    }

    //生成职位
    public static String getPosition(){
        String[] position = {"前端", "后端", "ui","需求", "人事", "前台", "大数据", "人工智能"};
        Integer num = new Random().nextInt(8);
        return position[num];
    }

    //生成分公司
    public static String getCompany(){
        Integer num = new Random().nextInt(4)+3;
        String string1 = "";
        for (int i = 0; i < num; i++){
            string1 = string1+CreateNameUtil.createChineseName();
        }
        String company = string1 + "有限公司";
        return company;
    }

}
